<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of user_model
 *
 * @author hoabui
 */
class user_model extends CI_Model {

    //put your code here
    function __construct() {
        parent::__construct();
    }

    function getAllUsers($page = 0, $page_size = PAGE_SIZE) {
        $this->db->limit($page_size, $page);
        $this->db->select('u.*');
        $this->db->from(tbl_user . ' u');
        $this->db->where('user_is_delete', 0);
        $query = $this->db->get();


        //Get total rows
        $this->db->select('user_id');
        $this->db->from(tbl_user);
        $this->db->where('user_is_delete', 0);
        $total = $this->db->count_all_results();

        $data = array('list' => $query->result(),
            'total' => $total);
        return $data;
    }

    function checkExist($user_name) {
        $this->db->select('user_name');
        $this->db->where('user_name', $user_name);
        $this->db->from(tbl_user);
        $query = $this->db->get();
        return $query->num_rows();
    }

    function addUser($info) {
        return $this->db->insert(tbl_user, $info);
    }

    function deleteUser($user_id) {
        $this->db->where('user_id', $user_id);
        return $this->db->update(tbl_user, array('user_is_delete' => 1));
    }

    function login($user_name, $password) {
        $this->db->where('user_name', $user_name);
        $this->db->where('password',$password);
        $this->db->where('user_is_delete',0);
        $query = $this->db->get("tb_users"); 
        $arr = $query->result();
        $count = $query->num_rows();
        if ($count <= 0)
            return null;
        return $arr[0];
    }

}

?>
